const { execSync, exec } = require('child_process');
const fs = require('fs');
const path = require('path');

const eslintFormat = (targetDir) => {
  // 查cwd是否有eslintrc文件
  const eslintConfigPath = path
    .join(global.cwdPath, './.eslintrc.js')
    .replace(/\\/g, '/');
  if (fs.existsSync(eslintConfigPath)) {
    exec(
      `eslint -c ${eslintConfigPath} --ext .tsx,.ts --fix ${targetDir}`,
      (error, stdout, stderr) => {
        console.log(stdout.toString());
        console.log(stderr.toString());
      }
    );
  }
  // 没有就直接输出
};

module.exports = eslintFormat;
